TAR
# m orden
pm <- 1:4
mod.list.tar<-list()
AIC.best.list<-list()
AICM = NULL
model.best <- list(d=0, p1=0, p2=0)
AIC.best = 10000
for(l in pm){
for(j in pm){
for(i in pm){
set.seed(777)
model.tar.s = tar(sactnetusd_train,p1=j,p2=i,d=l)
mod.list.tar[[paste(j,i,l,sep="-")]]<-model.tar.s$AIC
print(paste("Modelo:",j,i,l,sep="-"))
if (model.tar.s$AIC < AIC.best) {
AIC.best = model.tar.s$AIC
AIC.best.list[[paste(j,i,l,sep="-")]]<-AIC.best
#print("Modelo:",j,i,l,"AIC",AIC.best)
model.best$d = l
model.best$p1 = model.tar.s$p1
model.best$p2 = model.tar.s$p2
print(paste(model.tar.s$p1,model.tar.s$p2,l,sep="-")) }
}
}
}
# AICTar<-bind_rows(mod.list.tar,.id = "Ordene-delay")%>%
# arrange(`1`)
#
# knitr::kable(head(AICTar,20))
AICTarBest<-bind_rows(AIC.best.list,.id = "Ordene-delay")%>%
arrange(`1`)
knitr::kable(head(AICTarBest,20))
mod.tar1.usd<-TSA::tar(sactnetusd_train,p1=3,p2=4,d=1)
mod.tar2.usd<-TSA::tar(sactnetusd_train,p1=1,p2=2,d=1)
mod.tar3.usd<-TSA::tar(sactnetusd_train,p1=1,p2=3,d=1)
mod.tar1.usd$thd
##
## 622.0209
mod.tar2.usd$thd
##
## 670.8907
mod.tar3.usd$thd
##
## 691.3097
mod.tar1.usd$qr1$coefficients
## intercept-sactnetusd_train lag1-sactnetusd_train
## 181.4332347 1.6151098
## lag2-sactnetusd_train lag3-sactnetusd_train
## -1.3676001 0.4599062
mod.tar2.usd$qr1$coefficients
## intercept-sactnetusd_train lag1-sactnetusd_train
## 166.0529509 0.7379237
mod.tar3.usd$qr1$coefficients
## intercept-sactnetusd_train lag1-sactnetusd_train
## 132.9783554 0.7962717
mod.tar1.usd$qr2$coefficients
## intercept-sactnetusd_train lag1-sactnetusd_train
## 65.0189187 0.9439411
mod.tar2.usd$qr2$coefficients
## intercept-sactnetusd_train lag1-sactnetusd_train
## 83.4616216 0.9278156
mod.tar3.usd$qr2$coefficients
## intercept-sactnetusd_train lag1-sactnetusd_train
## 108.7318363 0.9060299
data.frame(
Modelo=c("p1=3,p2=4,d=1",
"p1=1,p2=2,d=1",
"p1=1,p2=3,d=1"),
AIC=c(mod.tar1.usd$AIC,
mod.tar2.usd$AIC,
mod.tar3.usd$AIC))%>%
arrange(AIC)%>%
knitr::kable()
| p1=3,p2=4,d=1 |
1323 |
| p1=1,p2=3,d=1 |
1346 |
| p1=1,p2=2,d=1 |
1357 |
tsdiag(mod.tar1.usd)

tsdiag(mod.tar2.usd)

tsdiag(mod.tar3.usd)

checkresiduals(ts(mod.tar1.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

checkresiduals(ts(mod.tar2.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

checkresiduals(ts(mod.tar3.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

prontar1.usd<- ts(as.vector(predict(mod.tar1.usd,n.ahead=7,n.sim=1000)$fit),start=c(2021,1),frequency = 12)
prontar2.usd<- ts(as.vector(predict(mod.tar2.usd,n.ahead=7,n.sim=1000)$fit),start=c(2021,1),frequency = 12)
prontar3.usd<- ts(as.vector(predict(mod.tar3.usd,n.ahead=7,n.sim=1000)$fit),start=c(2021,1),frequency = 12)
fit1.usd<-ts(as.vector(mod.tar1.usd$y)-as.vector(mod.tar1.usd$residuals),start =c(2011,1),frequency = 12)
## Warning in as.vector(mod.tar1.usd$y) - as.vector(mod.tar1.usd$residuals): longer
## object length is not a multiple of shorter object length
fit2.usd<-ts(as.vector(mod.tar1.usd$y)-mod.tar2.usd$residuals,start =c(2011,1),frequency = 12)
## Warning in as.vector(mod.tar1.usd$y) - mod.tar2.usd$residuals: longer object
## length is not a multiple of shorter object length
fit3.usd<-ts(as.vector(mod.tar1.usd$y)-mod.tar3.usd$residuals,start =c(2011,1),frequency = 12)
## Warning in as.vector(mod.tar1.usd$y) - mod.tar3.usd$residuals: longer object
## length is not a multiple of shorter object length
autoplot(sactnetusd_train)+
autolayer(fit1.usd)+
autolayer(fit2.usd)+
autolayer(fit3.usd)+
theme_bw()

data.frame(
Modelo=c("p1=3,p2=4,d=1",
"p1=1,p2=2,d=1",
"p1=1,p2=3,d=1"),
RMSE=c(
Metrics::rmse(sactnetusd_test, prontar1.usd),
Metrics::rmse(sactnetusd_test, prontar2.usd),
Metrics::rmse(sactnetusd_test, prontar3.usd)))%>%
arrange(RMSE)%>%
knitr::kable()
| p1=3,p2=4,d=1 |
325.7748 |
| p1=1,p2=2,d=1 |
350.3622 |
| p1=1,p2=3,d=1 |
378.1733 |
autoplot(sactnetusd_test)+
autolayer(prontar1.usd)+
autolayer(prontar2.usd)+
autolayer(prontar3.usd)+
theme_bw()

SETAR
Thus the threshold delay, the number of lags in each regime and the threshold value are computed.
Setar1.usd <-
selectSETAR(
sactnetusd_train,
include = c("const", "trend","none", "both"),
m = 4,
thDelay = seq(0, 3, by = 1),
nthresh = 3,
criterion = "AIC",
type = "level",
plot = T,
trace = T
)
## Using maximum autoregressive order for low regime: mL = 4
## Using maximum autoregressive order for high regime: mH = 4
## Searching on 80 possible threshold values within regimes with sufficient ( 15% ) number of observations
## Searching on 5120 combinations of thresholds ( 80 ), thDelay ( 4 ), mL ( 4 ) and MM ( 4 )
##
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776

Setar2.usd <-
selectSETAR(
sactnetusd_train,
m = 4,
d=2,
thDelay = seq(0, 3, by = 1),
nthresh = 3,
criterion = "AIC",
type = "level",
plot = T,
trace = T
)
## Using maximum autoregressive order for low regime: mL = 4
## Using maximum autoregressive order for high regime: mH = 4
## Searching on 78 possible threshold values within regimes with sufficient ( 15% ) number of observations
## Searching on 4992 combinations of thresholds ( 78 ), thDelay ( 4 ), mL ( 4 ) and MM ( 4 )
##
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776

Setar3.usd <-
selectSETAR(
sactnetusd_train,
m = 4,
thDelay = seq(0, 3, by = 1),
nthresh = 3,
d = 1,
criterion = "AIC",
type = "level",
plot = T,
trace = T
)
## Using maximum autoregressive order for low regime: mL = 4
## Using maximum autoregressive order for high regime: mH = 4
## Searching on 80 possible threshold values within regimes with sufficient ( 15% ) number of observations
## Searching on 5120 combinations of thresholds ( 80 ), thDelay ( 4 ), mL ( 4 ) and MM ( 4 )
##
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.131
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776
## 1 T: Trim not respected: 0.8534483 0.1465517 from th: 1212.776
## 1 T: Trim not respected: 0.862069 0.137931 from th: 1212.776
## 1 T: Trim not respected: 0.8706897 0.1293103 from th: 1212.776

Setar4.usd <-
selectSETAR(
sactnetusd_train,
m = 4,
thDelay = seq(0, 3, by = 1),
nthresh = 3,
d = 2,
criterion = "AIC",
type = "level",
plot = T,
trace = T
)
## Using maximum autoregressive order for low regime: mL = 4
## Using maximum autoregressive order for high regime: mH = 4
## Searching on 78 possible threshold values within regimes with sufficient ( 15% ) number of observations
## Searching on 4992 combinations of thresholds ( 78 ), thDelay ( 4 ), mL ( 4 ) and MM ( 4 )
##
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1202.79
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1207.644
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8571429 0.1428571 from th: 1208.27
## 1 T: Trim not respected: 0.875 0.125 from th: 1208.27
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.131
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.131
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776
## 1 T: Trim not respected: 0.8660714 0.1339286 from th: 1212.776
## 1 T: Trim not respected: 0.8839286 0.1160714 from th: 1212.776
## 1 T: Trim not respected: 0.9017857 0.09821429 from th: 1212.776

Setar1.usd$allTh%>%
as.data.frame()%>%
arrange(AIC,thDelay,mL,mH)%>%
head(5)
## thDelay mL mH th AIC
## 1 2 1 3 1208.270 1035.463
## 2 2 1 3 1207.644 1035.873
## 3 2 1 3 1202.790 1035.887
## 4 1 1 1 1202.790 1036.336
## 5 1 2 1 1182.401 1036.624
Setar2.usd$allTh%>%
as.data.frame()%>%
arrange(AIC,thDelay,mL,mH)%>%
head(5)
## thDelay mL mH th AIC
## 1 0 1 4 1182.4010 1100.897
## 2 2 3 1 785.7637 1101.222
## 3 1 3 1 691.3097 1101.489
## 4 1 3 3 691.3097 1101.540
## 5 0 1 4 1193.4284 1101.591
Setar3.usd$allTh%>%
as.data.frame()%>%
arrange(AIC,thDelay,mL,mH)%>%
head(5)
## thDelay mL mH th AIC
## 1 2 1 3 1208.270 1035.463
## 2 2 1 3 1207.644 1035.873
## 3 2 1 3 1202.790 1035.887
## 4 1 1 1 1202.790 1036.336
## 5 1 2 1 1182.401 1036.624
Setar4.usd$allTh%>%
as.data.frame()%>%
arrange(AIC,thDelay,mL,mH)%>%
head(5)
## thDelay mL mH th AIC
## 1 0 1 4 1182.4010 1100.897
## 2 2 3 1 785.7637 1101.222
## 3 1 3 1 691.3097 1101.489
## 4 1 3 3 691.3097 1101.540
## 5 0 1 4 1193.4284 1101.591
modeloas1.usd <-
setar(
sactnetusd_train,
mL = 1,
mH = 3,
d=1,
nthresh = 1,
thDelay = 2,
type = "level"
)
##
## 1 T: Trim not respected: 0.8632479 0.1367521 from th: 1212.776
## Warning: Possible unit root in the high regime. Roots are: 1.0041 1.0041 0.9829
## Raiz Unitaria
summary(modeloas1.usd) #residuals variance = 0.005525, AIC = -632, MAPE = 0.4352%
##
## Non linear autoregressive model
##
## SETAR model ( 2 regimes)
## Coefficients:
## Low regime:
## const.L phiL.1
## 37.5800433 0.9690969
##
## High regime:
## const.H phiH.1 phiH.2 phiH.3
## -67.137862 1.105962 -1.081897 1.009118
##
## Threshold:
## -Variable: Z(t) = + (0) X(t)+ (0)X(t-1)+ (1)X(t-2)
## -Value: 1208
## Proportion of points in low regime: 83.76% High regime: 16.24%
##
## Residuals:
## Min 1Q Median 3Q Max
## -140.7273 -48.8234 -9.7786 36.9904 227.4330
##
## Fit:
## residuals variance = 5036, AIC = 1037, MAPE = 5.9%
##
## Coefficient(s):
##
## Estimate Std. Error t value Pr(>|t|)
## const.L 37.580043 31.407394 1.1965 0.233970
## phiL.1 0.969097 0.031934 30.3472 < 2.2e-16 ***
## const.H -67.137862 207.413771 -0.3237 0.746765
## phiH.1 1.105962 0.215038 5.1431 1.134e-06 ***
## phiH.2 -1.081897 0.345016 -3.1358 0.002181 **
## phiH.3 1.009118 0.316420 3.1892 0.001843 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Threshold
## Variable: Z(t) = + (0) X(t) + (0) X(t-1)+ (1) X(t-2)
##
## Value: 1208
# plot(modeloas1)
checkresiduals(ts(modeloas1.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

modeloas2.usd <-
setar(
sactnetusd_train,
mL = 3,
mH = 1,
d=2,
nthresh = 1,
thDelay = 1,
type = "level"
)
##
## 1 T: Trim not respected: 0.8596491 0.1403509 from th: 1212.381
## Warning: Possible unit root in the low regime. Roots are: 0.9303 1.143 0.9303
## Raiz Unitaria
summary(modeloas2.usd) # residuals variance = 0.005857, AIC = -635, MAPE = 0.4584%
##
## Non linear autoregressive model
##
## SETAR model ( 2 regimes)
## Coefficients:
## Low regime:
## const.L phiL.1 phiL.2 phiL.3
## 858.2495437 0.5731090 0.1113798 -1.0108432
##
## High regime:
## const.H phiH.1
## 258.7562047 0.7787606
##
## Threshold:
## -Variable: Z(t) = + (0) X(t)+ (1)X(t-1)+ (0)X(t-2)
## -Value: 785.8
## Proportion of points in low regime: 22.81% High regime: 77.19%
##
## Residuals:
## Min 1Q Median 3Q Max
## -267.8547 -64.4825 -8.4419 55.1728 308.2301
##
## Fit:
## residuals variance = 8762, AIC = 1103, MAPE = 7.549%
##
## Coefficient(s):
##
## Estimate Std. Error t value Pr(>|t|)
## const.L 858.249544 248.319565 3.4562 0.0007705 ***
## phiL.1 0.573109 0.195945 2.9249 0.0041589 **
## phiL.2 0.111380 0.308654 0.3609 0.7188742
## phiL.3 -1.010843 0.297348 -3.3995 0.0009310 ***
## const.H 258.756205 76.771445 3.3705 0.0010249 **
## phiH.1 0.778761 0.068832 11.3140 < 2.2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Threshold
## Variable: Z(t) = + (0) X(t) + (1) X(t-1)+ (0) X(t-2)
##
## Value: 785.8
# plot(modeloas2)
checkresiduals(ts(modeloas2.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

modeloas3.usd <-
setar(
sactnetusd_train,
mL = 1,
mH = 1,
d=1,
nthresh = 1,
thDelay = 1,
type = "level"
)
##
## 1 T: Trim not respected: 0.8559322 0.1440678 from th: 1212.776
## Warning: Possible unit root in the high regime. Roots are: 0.926
## Warning: Possible unit root in the low regime. Roots are: 0.9973
## Raiz Unitaria
summary(modeloas3.usd) # residuals variance = 0.006319, AIC = -621, MAPE = 0.4621%
##
## Non linear autoregressive model
##
## SETAR model ( 2 regimes)
## Coefficients:
## Low regime:
## const.L phiL.1
## 14.375566 1.002708
##
## High regime:
## const.H phiH.1
## -139.242572 1.079965
##
## Threshold:
## -Variable: Z(t) = + (0) X(t)+ (1)X(t-1)
## -Value: 1203
## Proportion of points in low regime: 81.36% High regime: 18.64%
##
## Residuals:
## Min 1Q Median 3Q Max
## -143.9335 -53.2829 -5.4996 50.1964 240.7517
##
## Fit:
## residuals variance = 5265, AIC = 1038, MAPE = 6.015%
##
## Coefficient(s):
##
## Estimate Std. Error t value Pr(>|t|)
## const.L 14.375566 33.188627 0.4331 0.6657
## phiL.1 1.002708 0.034585 28.9927 < 2.2e-16 ***
## const.H -139.242572 155.823087 -0.8936 0.3734
## phiH.1 1.079965 0.121916 8.8583 1.111e-14 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Threshold
## Variable: Z(t) = + (0) X(t) + (1) X(t-1)
##
## Value: 1203
# plot(modeloas3)
checkresiduals(ts(modeloas3.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

modeloas4.usd <-
setar(
sactnetusd_train,
m = 3,
mL = 1,
mH = 2,
d=2,
nthresh = 1,
thDelay = 0,
type = "level"
)
## Warning: Possible unit root in the high regime. Roots are: 0.8301 6.3855
## Warning: Possible unit root in the low regime. Roots are: 0.9875
summary(modeloas4.usd) # residuals variance = 0.006319, AIC = -621, MAPE = 0.4621%
##
## Non linear autoregressive model
##
## SETAR model ( 2 regimes)
## Coefficients:
## Low regime:
## const.L phiL.1
## 22.905069 1.012612
##
## High regime:
## const.H phiH.1 phiH.2
## -351.2749796 1.0481121 0.1886645
##
## Threshold:
## -Variable: Z(t) = + (1) X(t)+ (0)X(t-1)+ (0)X(t-2)
## -Value: 1193
## Proportion of points in low regime: 78.95% High regime: 21.05%
##
## Residuals:
## Min 1Q Median 3Q Max
## -234.1334 -76.6856 2.1224 61.6316 277.0180
##
## Fit:
## residuals variance = 9172, AIC = 1107, MAPE = 8.311%
##
## Coefficient(s):
##
## Estimate Std. Error t value Pr(>|t|)
## const.L 22.905069 47.818727 0.4790 0.6328
## phiL.1 1.012612 0.050424 20.0821 < 2.2e-16 ***
## const.H -351.274980 251.367333 -1.3975 0.1650
## phiH.1 1.048112 0.246488 4.2522 4.33e-05 ***
## phiH.2 0.188664 0.192645 0.9793 0.3295
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Threshold
## Variable: Z(t) = + (1) X(t) + (0) X(t-1)+ (0) X(t-2)
##
## Value: 1193
# plot(modeloas4)
checkresiduals(ts(modeloas4.usd$residuals,start=c(2011,1),frequency = 12))
## Warning in modeldf.default(object): Could not find appropriate degrees of
## freedom for this model.

AIC(modeloas1.usd)
## [1] 1036.912
AIC(modeloas2.usd)
## [1] 1103.381
AIC(modeloas3.usd)
## [1] 1038.25
AIC(modeloas4.usd)
## [1] 1106.873
pronsetar1.usd<- predict(modeloas1.usd, n.ahead = 7)
pronsetar2.usd<- predict(modeloas2.usd, n.ahead = 7)
pronsetar3.usd<- predict(modeloas3.usd, n.ahead = 7)
pronsetar4.usd<- predict(modeloas4.usd, n.ahead = 7)
fit1.usd<-ts(modeloas1.usd$fitted.values,start =c(2011,1),frequency = 12)
fit2.usd<-ts(modeloas2.usd$fitted.values,start =c(2011,1),frequency = 12)
fit3.usd<-ts(modeloas3.usd$fitted.values,start =c(2011,1),frequency = 12)
fit4.usd<-ts(modeloas4.usd$fitted.values,start =c(2011,1),frequency = 12)
autoplot(sactnetusd_train)+
autolayer(fit1.usd)+
autolayer(fit2.usd)+
autolayer(fit3.usd)+
autolayer(fit4.usd)+
theme_bw()

data.frame(
Modelo= c(
"1) m = 3,mL = 3,mH = 1, d=1",
"2) m = 3,mL = 2,mH = 3, d=2",
"3) m = 3,mL = 3,mH = 2, d=1",
"4) m = 3,mL = 1,mH = 2, d=2"
),
RMSE=c(
Metrics::rmse(sactnetusd_test, pronsetar1.usd),
Metrics::rmse(sactnetusd_test, pronsetar2.usd),
Metrics::rmse(sactnetusd_test, pronsetar3.usd),
Metrics::rmse(sactnetusd_test, pronsetar4.usd)))%>%
arrange(RMSE)%>%
knitr::kable()
| 4) m = 3,mL = 1,mH = 2, d=2 |
269.2250 |
| 1) m = 3,mL = 3,mH = 1, d=1 |
378.0577 |
| 3) m = 3,mL = 3,mH = 2, d=1 |
380.1196 |
| 2) m = 3,mL = 2,mH = 3, d=2 |
389.9989 |
autoplot(sactnetusd_test)+
autolayer(pronsetar1.usd)+
autolayer(pronsetar2.usd)+
autolayer(pronsetar3.usd)+
autolayer(pronsetar4.usd)+
theme_bw()
